const axios = require("axios");
const cheerio = require("cheerio");

// 获取近期大作模块数据
async function getYouxiaTypeGame(type) {
  const res = await axios.get("https://0day.ali213.net/");
  return getYouxiaTypeDetail(res.data, type, "https://0day.ali213.net/");
}

function getYouxiaTypeDetail(page, type, baseUrl) {
  const $ = cheerio.load(page);
  let index = 0;
  let typeList = [];
  $(".s2-left-con .s2-left-list").each(function () {
    if (index === type + 1) {
      $(".item-img-con a", this).each(function () {
        const item = {};
        item.name = $(this).attr("title");
        item.link = `${baseUrl}${$(this).attr("href")}`;
        item.img = "https:" + $("div img", this).attr("src");
        item.score = $("span", this).text();
        typeList.push(item);
      });
    }
    index++;
  });
  return typeList;
}

module.exports = getYouxiaTypeGame;
